package com.hl.ruoyicsmshop.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hl.ruoyicsmshop.domain.GroupActivity;
import com.hl.ruoyicsmshop.service.IGroupActivityService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 拼团活动Controller
 * 
 * @author ruoyi
 * @date 2025-08-09
 */
@RestController
@RequestMapping("/joinGroup")
public class GroupActivityController extends BaseController
{
    @Autowired
    private IGroupActivityService groupActivityService;

    /**
     * 查询拼团活动列表
     */
    @RequiresPermissions("csmshop:joinGroup:list")
    @GetMapping("/list")
    public TableDataInfo list(GroupActivity groupActivity)
    {
        startPage();
        List<GroupActivity> list = groupActivityService.selectGroupActivityList(groupActivity);
        return getDataTable(list);
    }

    /**
     * 导出拼团活动列表
     */
    @RequiresPermissions("csmshop:joinGroup:export")
    @Log(title = "拼团活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupActivity groupActivity)
    {
        List<GroupActivity> list = groupActivityService.selectGroupActivityList(groupActivity);
        ExcelUtil<GroupActivity> util = new ExcelUtil<GroupActivity>(GroupActivity.class);
        util.exportExcel(response, list, "拼团活动数据");
    }

    /**
     * 获取拼团活动详细信息
     */
    @RequiresPermissions("csmshop:joinGroup:query")
    @GetMapping(value = "/{gaId}")
    public AjaxResult getInfo(@PathVariable("gaId") Long gaId)
    {
        return success(groupActivityService.selectGroupActivityByGaId(gaId));
    }

    /**
     * 新增拼团活动
     */
    @RequiresPermissions("csmshop:joinGroup:add")
    @Log(title = "拼团活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupActivity groupActivity)
    {
        return toAjax(groupActivityService.insertGroupActivity(groupActivity));
    }

    /**
     * 修改拼团活动
     */
    @RequiresPermissions("csmshop:joinGroup:edit")
    @Log(title = "拼团活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupActivity groupActivity)
    {
        return toAjax(groupActivityService.updateGroupActivity(groupActivity));
    }

    /**
     * 删除拼团活动
     */
    @RequiresPermissions("csmshop:joinGroup:remove")
    @Log(title = "拼团活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gaIds}")
    public AjaxResult remove(@PathVariable Long[] gaIds)
    {
        return toAjax(groupActivityService.deleteGroupActivityByGaIds(gaIds));
    }
}
